package cn.starlightsoftware.sherly.validation;

import cn.hutool.core.util.PhoneUtil;
import cn.hutool.core.util.StrUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author 谷子毅
 * @date 2024/4/27
 */
public class PhoneValidator implements ConstraintValidator<Phone, String> {
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        // 为空则交给其他校验器校验
        if (StrUtil.isBlank(value)) {
            return true;
        }
        // 校验手机
        return PhoneUtil.isPhone(value);
    }
}
